package com.game.base.server.upgrade;

import android.content.Context;

import com.game.base.utils.log.Logger;
import com.game.base.utils.toast.ToastUtil;
import com.game.base.view.dialog.DialogUtils;

import cn.bmob.v3.update.BmobUpdateAgent;

/**
 * 应用升级服务
 * Created by Su on 2019/5/20.
 */
public class UpgradeMgr {
    /**
     * 检测更新
     */
    public static void checkUpdate(Context context, boolean isForce) {
        if (isForce) {
            DialogUtils.showLoadingDialog(context, "更新检查...");
        }
        BmobUpdateAgent.setUpdateOnlyWifi(false);
        BmobUpdateAgent.setUpdateListener((updateStatus, updateResponse) -> {
            Logger.d("updateStatus: " + updateStatus + ",  " + updateResponse.version_i);

            if (isForce) {
                DialogUtils.closeTipDialog();
                if (updateStatus == 1) {
                    ToastUtil.showShort("当前为最新版本");
                }
            }
        });

        if (isForce) {
            BmobUpdateAgent.forceUpdate(context);
            return;
        }
        BmobUpdateAgent.update(context);
    }
}
